home *** CD-ROM | disk | FTP | other *** search
/ Computer Select (Limited Edition) / Computer Select.iso / dobbs / v17n03 / dflt10.exe / MEMOPAD.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-09  |  17.9 KB  |  606 lines

  1. /* --------------- memopad.c ----------- */
  2.  
  3. #include "dflat.h"
  4.  
  5. extern DBOX PrintSetup;
  6.  
  7. char DFlatApplication[] = "MemoPad";
  8.  
  9. static char Untitled[] = "Untitled";
  10. static int wndpos;
  11.  
  12. static int MemoPadProc(WINDOW, MESSAGE, PARAM, PARAM);
  13. static void NewFile(WINDOW);
  14. static void SelectFile(WINDOW);
  15. static void PadWindow(WINDOW, char *);
  16. static void OpenPadWindow(WINDOW, char *);
  17. static void LoadFile(WINDOW);
  18. static void PrintPad(WINDOW);
  19. static void SaveFile(WINDOW, int);
  20. static void DeleteFile(WINDOW);
  21. static int EditorProc(WINDOW, MESSAGE, PARAM, PARAM);
  22. static char *NameComponent(char *);
  23. static int PrintSetupProc(WINDOW, MESSAGE, PARAM, PARAM);
  24. static void FixTabMenu(void);
  25. #ifndef TURBOC
  26. void Calendar(WINDOW);
  27. #endif
  28. void BarChart(WINDOW);
  29. char **Argv;
  30.  
  31. static int CancelPrint;
  32. #define CHARSLINE 80
  33. #define LINESPAGE 66
  34.  
  35. void main(int argc, char *argv[])
  36. {
  37.     WINDOW wnd;
  38.     init_messages();
  39.     Argv = argv;
  40.     wnd = CreateWindow(APPLICATION,
  41.                         "D-Flat MemoPad " VERSION,
  42.                         0, 0, -1, -1,
  43.                         &MainMenu,
  44.                         NULL,
  45.                         MemoPadProc,
  46.                         MOVEABLE  |
  47.                         SIZEABLE  |
  48.                         HASBORDER |
  49.                         HASSTATUSBAR
  50.                         );
  51.  
  52.     SendMessage(wnd, SETFOCUS, TRUE, 0);
  53.     while (argc > 1)    {
  54.         PadWindow(wnd, argv[1]);
  55.         --argc;
  56.         argv++;
  57.     }
  58.     while (dispatch_message())
  59.         ;
  60. }
  61. /* ------ open text files and put them into editboxes ----- */
  62. static void PadWindow(WINDOW wnd, char *FileName)
  63. {
  64.     int ax, criterr = 1;
  65.     struct ffblk ff;
  66.     char path[64];
  67.     char *cp;
  68.  
  69.     CreatePath(path, FileName, FALSE, FALSE);
  70.     cp = path+strlen(path);
  71.     CreatePath(path, FileName, TRUE, FALSE);
  72.     while (criterr == 1)    {
  73.         ax = findfirst(path, &ff, 0);
  74.         criterr = TestCriticalError();
  75.     }
  76.     while (ax == 0 && !criterr)    {
  77.         strcpy(cp, ff.ff_name);
  78.         OpenPadWindow(wnd, path);
  79.         ax = findnext(&ff);
  80.     }
  81. }
  82. /* ------- window processing module for the
  83.                     memopad application window ----- */
  84. static int MemoPadProc(WINDOW wnd,MESSAGE msg,PARAM p1,PARAM p2)
  85. {
  86.     int rtn;
  87.     switch (msg)    {
  88.         case CREATE_WINDOW:
  89.             rtn = DefaultWndProc(wnd, msg, p1, p2);
  90.             if (cfg.InsertMode)
  91.                 SetCommandToggle(&MainMenu, ID_INSERT);
  92.             if (cfg.WordWrap)
  93.                 SetCommandToggle(&MainMenu, ID_WRAP);
  94.             FixTabMenu();
  95.             return rtn;
  96.         case COMMAND:
  97.             switch ((int)p1)    {
  98.                 case ID_NEW:
  99.                     NewFile(wnd);
  100.                     return TRUE;
  101.                 case ID_OPEN:
  102.                     SelectFile(wnd);
  103.                     return TRUE;
  104.                 case ID_SAVE:
  105.                     SaveFile(inFocus, FALSE);
  106.                     return TRUE;
  107.                 case ID_SAVEAS:
  108.                     SaveFile(inFocus, TRUE);
  109.                     return TRUE;
  110.                 case ID_DELETEFILE:
  111.                     DeleteFile(inFocus);
  112.                     return TRUE;
  113.                 case ID_PRINTSETUP:
  114.                     DialogBox(wnd, &PrintSetup, TRUE, PrintSetupProc);
  115.                     return TRUE;
  116.                 case ID_PRINT:
  117.                     PrintPad(inFocus);
  118.                     return TRUE;
  119.                 case ID_TAB2:
  120.                     cfg.Tabs = 2;
  121.                     FixTabMenu();
  122.                     return TRUE;
  123.                 case ID_TAB4:
  124.                     cfg.Tabs = 4;
  125.                     FixTabMenu();
  126.                     return TRUE;
  127.                 case ID_TAB6:
  128.                     cfg.Tabs = 6;                    
  129.                     FixTabMenu();
  130.                     return TRUE;
  131.                 case ID_TAB8:
  132.                     cfg.Tabs = 8;
  133.                     FixTabMenu();
  134.                     return TRUE;
  135.                 case ID_CANCEL:
  136.                     if ((int)p2 == 0)
  137.                         CancelPrint = TRUE;
  138.                     return TRUE;
  139.                 case ID_CALENDAR:
  140. #ifndef TURBOC
  141.                     Calendar(wnd);
  142. #endif
  143.                     return TRUE;
  144.                 case ID_BARCHART:
  145.                     BarChart(wnd);
  146.                     return TRUE;
  147.                 case ID_ABOUT:
  148.                     MessageBox(
  149.                          "About D-Flat and the MemoPad",
  150.                         "   ┌───────────────────────┐\n"
  151.                         "   │    ▄▄▄   ▄▄▄     ▄    │\n"
  152.                         "   │    █  █  █  █    █    │\n"
  153.                         "   │    █  █  █  █    █    │\n"
  154.                         "   │    █  █  █  █ █  █    │\n"
  155.                         "   │    ▀▀▀   ▀▀▀   ▀▀     │\n"
  156.                         "   └───────────────────────┘\n"
  157.                         "D-Flat implements the SAA/CUA\n"
  158.                         "interface in a public domain\n"
  159.                         "C language library originally\n"
  160.                         "published in Dr. Dobb's Journal\n"
  161.                         "    ------------------------ \n"
  162.                         "MemoPad is a multiple document\n"
  163.                         "editor that demonstrates D-Flat");
  164.                     return TRUE;
  165.                 default:
  166.                     break;
  167.             }
  168.             break;
  169.         default:
  170.             break;
  171.     }
  172.     return DefaultWndProc(wnd, msg, p1, p2);
  173. }
  174. /* --- The New command. Open an empty editor window --- */
  175. static void NewFile(WINDOW wnd)
  176. {
  177.     OpenPadWindow(wnd, Untitled);
  178. }
  179. /* --- The Open... command. Select a file  --- */
  180. static void SelectFile(WINDOW wnd)
  181. {
  182.     char FileName[64];
  183.     if (OpenFileDialogBox("*.PAD", FileName))    {
  184.         /* --- see if the document is already in a window --- */
  185.         WINDOW wnd1 = GetFirstChild(wnd);
  186.         while (wnd1 != NULL)    {
  187.             if (stricmp(FileName, wnd1->extension) == 0)    {
  188.                 SendMessage(wnd1, SETFOCUS, TRUE, 0);
  189.                 SendMessage(wnd1, RESTORE, 0, 0);
  190.                 return;
  191.             }
  192.             wnd1 = GetNextChild(wnd, wnd1);
  193.         }
  194.         OpenPadWindow(wnd, FileName);
  195.     }
  196. }
  197.  
  198. /* --- open a document window and load a file --- */
  199. static void OpenPadWindow(WINDOW wnd, char *FileName)
  200. {
  201.     static WINDOW wnd1 = NULL;
  202.     struct stat sb;
  203.     char *Fname = FileName;
  204.     char *ermsg;
  205.     if (strcmp(FileName, Untitled))    {
  206.         if (stat(FileName, &sb))    {
  207.             if ((ermsg = malloc(strlen(FileName)+20)) != NULL) {
  208.                 strcpy(ermsg, "No such file as\n");
  209.                 strcat(ermsg, FileName);
  210.                 ErrorMessage(ermsg);
  211.                 free(ermsg);
  212.             }
  213.             return;
  214.         }
  215.         Fname = NameComponent(FileName);
  216.     }
  217.     wndpos += 2;
  218.     if (wndpos == 20)
  219.         wndpos = 2;
  220.     wnd1 = CreateWindow(EDITBOX,
  221.                 Fname,
  222.                 (wndpos-1)*2, wndpos, 10, 40,
  223.                 NULL, wnd, EditorProc,
  224.                 SHADOW     |
  225.                 MINMAXBOX  |
  226.                 CONTROLBOX |
  227.                 VSCROLLBAR |
  228.                 HSCROLLBAR |
  229.                 MOVEABLE   |
  230.                 HASBORDER  |
  231.                 SIZEABLE   |
  232.                 MULTILINE
  233.     );
  234.     if (strcmp(FileName, Untitled))    {
  235.         if ((wnd1->extension = malloc(strlen(FileName)+1)) != NULL)    {
  236.             strcpy(wnd1->extension, FileName);
  237.             LoadFile(wnd1);
  238.         }
  239.     }
  240.     SendMessage(wnd1, SETFOCUS, TRUE, 0);
  241. }
  242. /* --- Load the notepad file into the editor text buffer --- */
  243. static void LoadFile(WINDOW wnd)
  244. {
  245.     char *Buf = NULL;
  246.     int recptr = 0;
  247.     FILE *fp;
  248.  
  249.     if ((fp = fopen(wnd->extension, "rt")) != NULL)    {
  250.         while (!feof(fp))    {
  251.             if ((Buf = realloc(Buf, recptr+150)) == NULL)
  252.                 break;
  253.             fgets(Buf+recptr, 150, fp);
  254.             recptr += strlen(Buf+recptr);
  255.         }
  256.         fclose(fp);
  257.         if (Buf != NULL)    {
  258.             SendMessage(wnd, SETTEXT, (PARAM) Buf, 0);
  259.             free(Buf);
  260.         }
  261.     }
  262. }
  263. /* --- print the current notepad --- */
  264. static void PrintPad(WINDOW wnd)
  265. {
  266.     unsigned char *text;
  267.     FILE *prn;
  268.     int LineCtr = 0, CharCtr = 0;
  269.  
  270.     if (*cfg.PrinterPort)    {
  271.         if ((prn = fopen(cfg.PrinterPort, "wt")) != NULL)    {
  272.             /* ---- get the address of the editor text ----- */
  273.             text = GetText(wnd);
  274.             CancelPrint = FALSE;
  275.             CancelBox(GetParent(wnd), "Printing...");
  276.             /* ------- print the notepad text --------- */
  277.             while (*text)    {
  278.                 int i;
  279.                 dispatch_message();
  280.                 if (CancelPrint)
  281.                     if (YesNoBox("Cancel Printing?"))
  282.                         break;
  283.                 CancelPrint = FALSE;
  284.                 if (*text == '\n' || CharCtr == cfg.RightMargin)    {
  285.                     fputs("\r\n", prn);
  286.                     LineCtr++;
  287.                     if (LineCtr == cfg.BottomMargin)    {
  288.                         fputc('\f', prn);
  289.                         for (i = 0; i < cfg.TopMargin; i++)
  290.                             fputc('\n', prn);
  291.                         LineCtr = cfg.TopMargin;
  292.                     }
  293.                     CharCtr = 0;
  294.                     if (*text == '\n')    {
  295.                         text++;
  296.                         continue;
  297.                     }
  298.                 }
  299.                 if (CharCtr == 0)    {
  300.                     for (i = 0; i < cfg.LeftMargin; i++)    {
  301.                         fputc(' ', prn);
  302.                         CharCtr++;
  303.                     }
  304.                 }
  305.                 CharCtr++;
  306.                 fputc(*text++, prn);
  307.             }
  308.             CloseCancelBox();
  309.  
  310.             /* ------- follow with a form feed? --------- */
  311.             if (YesNoBox("Form Feed?"))
  312.                 fputc('\f', prn);
  313.             fclose(prn);
  314.         }
  315.         else
  316.             ErrorMessage("Cannot open printer file");
  317.     }
  318.     else
  319.         ErrorMessage("No printer selected");
  320. }
  321. /* ---------- save a file to disk ------------ */
  322. static void SaveFile(WINDOW wnd, int Saveas)
  323. {
  324.     FILE *fp;
  325.     if (wnd->extension == NULL || Saveas)    {
  326.         char FileName[64];
  327.         if (SaveAsDialogBox(FileName))    {
  328.             if (wnd->extension != NULL)
  329.                 free(wnd->extension);
  330.             if ((wnd->extension =
  331.                     malloc(strlen(FileName)+1)) != NULL)    {
  332.                 strcpy(wnd->extension, FileName);
  333.                 AddTitle(wnd, NameComponent(FileName));
  334.                 SendMessage(wnd, BORDER, 0, 0);
  335.             }
  336.         }
  337.         else
  338.             return;
  339.     }
  340.     if (wnd->extension != NULL)    {
  341.         WINDOW mwnd = MomentaryMessage("Saving the file");
  342.         if ((fp = fopen(wnd->extension, "wt")) != NULL)    {
  343.             fwrite(GetText(wnd), strlen(GetText(wnd)), 1, fp);
  344.             fclose(fp);
  345.             wnd->TextChanged = FALSE;
  346.         }
  347.         SendMessage(mwnd, CLOSE_WINDOW, 0, 0);
  348.     }
  349. }
  350. /* -------- delete a file ------------ */
  351. static void DeleteFile(WINDOW wnd)
  352. {
  353.     if (wnd->extension != NULL)    {
  354.         if (strcmp(wnd->extension, Untitled))    {
  355.             char *fn = NameComponent(wnd->extension);
  356.             if (fn != NULL)    {
  357.                 char msg[30];
  358.                 sprintf(msg, "Delete %s?", fn);
  359.                 if (YesNoBox(msg))    {
  360.                     unlink(wnd->extension);
  361.                     SendMessage(wnd, CLOSE_WINDOW, 0, 0);
  362.                 }
  363.             }
  364.         }
  365.     }
  366. }
  367. /* ------ display the row and column in the statusbar ------ */
  368. static void ShowPosition(WINDOW wnd)
  369. {
  370.     char status[30];
  371.     sprintf(status, "Line:%4d  Column: %2d",
  372.         wnd->CurrLine, wnd->CurrCol);
  373.     SendMessage(GetParent(wnd), ADDSTATUS, (PARAM) status, 0);
  374. }
  375. /* ----- window processing module for the editboxes ----- */
  376. static int EditorProc(WINDOW wnd,MESSAGE msg,PARAM p1,PARAM p2)
  377. {
  378.     int rtn;
  379.     switch (msg)    {
  380.         case SETFOCUS:
  381.             if ((int)p1)    {
  382.                 wnd->InsertMode = GetCommandToggle(&MainMenu, ID_INSERT);
  383.                 wnd->WordWrapMode = GetCommandToggle(&MainMenu, ID_WRAP);
  384.             }
  385.             rtn = DefaultWndProc(wnd, msg, p1, p2);
  386.             if ((int)p1 == FALSE)
  387.                 SendMessage(GetParent(wnd), ADDSTATUS, 0, 0);
  388.             else 
  389.                 ShowPosition(wnd);
  390.             return rtn;
  391.         case KEYBOARD_CURSOR:
  392.             rtn = DefaultWndProc(wnd, msg, p1, p2);
  393.             ShowPosition(wnd);
  394.             return rtn;
  395.         case COMMAND:
  396.             switch ((int) p1)    {
  397.                 case ID_SEARCH:
  398.                     SearchText(wnd);
  399.                     return TRUE;
  400.                 case ID_REPLACE:
  401.                     ReplaceText(wnd);
  402.                     return TRUE;
  403.                 case ID_SEARCHNEXT:
  404.                     SearchNext(wnd);
  405.                     return TRUE;
  406.                 case ID_CUT:
  407.                     CopyToClipboard(wnd);
  408.                     SendMessage(wnd, COMMAND, ID_DELETETEXT, 0);
  409.                     SendMessage(wnd, PAINT, 0, 0);
  410.                     return TRUE;
  411.                 case ID_COPY:
  412.                     CopyToClipboard(wnd);
  413.                     ClearTextBlock(wnd);
  414.                     SendMessage(wnd, PAINT, 0, 0);
  415.                     return TRUE;
  416.                 case ID_PASTE:
  417.                     PasteFromClipboard(wnd);
  418.                     SendMessage(wnd, PAINT, 0, 0);
  419.                     return TRUE;
  420.                 case ID_HELP:
  421.                     DisplayHelp(wnd, "MEMOPADDOC");
  422.                     return TRUE;
  423.                 case ID_WRAP:
  424.                     wnd->WordWrapMode = GetCommandToggle(&MainMenu, ID_WRAP);
  425.                     cfg.WordWrap = wnd->WordWrapMode;
  426.                     return TRUE;
  427.                 case ID_INSERT:
  428.                     wnd->InsertMode = GetCommandToggle(&MainMenu, ID_INSERT);
  429.                     cfg.InsertMode = wnd->InsertMode;
  430.                     SendMessage(NULL, SHOW_CURSOR, wnd->InsertMode, 0);
  431.                     return TRUE;
  432.                 default:
  433.                     break;
  434.             }
  435.             break;
  436.         case CLOSE_WINDOW:
  437.             if (wnd->TextChanged)    {
  438.                 char *cp = malloc(25+strlen(GetTitle(wnd)));
  439.                 SendMessage(wnd, SETFOCUS, TRUE, 0);
  440.                 if (cp != NULL)    {
  441.                     strcpy(cp, GetTitle(wnd));
  442.                     strcat(cp, "\nText changed. Save it?");
  443.                     if (YesNoBox(cp))
  444.                         SendMessage(GetParent(wnd),
  445.                             COMMAND, ID_SAVE, 0);
  446.                     free(cp);
  447.                 }
  448.             }
  449.             wndpos = 0;
  450.             if (wnd->extension != NULL)    {
  451.                 free(wnd->extension);
  452.                 wnd->extension = NULL;
  453.             }
  454.             break;
  455.         default:
  456.             break;
  457.     }
  458.     return DefaultWndProc(wnd, msg, p1, p2);
  459. }
  460. /* -- point to the name component of a file specification -- */
  461. static char *NameComponent(char *FileName)
  462. {
  463.     char *Fname;
  464.     if ((Fname = strrchr(FileName, '\\')) == NULL)
  465.         if ((Fname = strrchr(FileName, ':')) == NULL)
  466.             Fname = FileName-1;
  467.     return Fname + 1;
  468. }
  469.  
  470. static char *ports[] = {
  471.     "Lpt1",    "Lpt2",    "Lpt3",
  472.     "Com1",    "Com2",    "Com3",    "Com4",
  473.       NULL
  474. };
  475.  
  476. static int PrintSetupProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
  477. {
  478.     int rtn, i = 0, mar;
  479.     char marg[10];
  480.     WINDOW cwnd;
  481.     switch (msg)    {
  482.         case CREATE_WINDOW:
  483.             rtn = DefaultWndProc(wnd, msg, p1, p2);
  484.             PutItemText(wnd, ID_PRINTERPORT, cfg.PrinterPort);
  485.             while (ports[i] != NULL)
  486.                 PutComboListText(wnd, ID_PRINTERPORT, ports[i++]);
  487.             for (mar = CHARSLINE; mar >= 0; --mar)    {
  488.                 sprintf(marg, "%3d", mar);
  489.                 PutItemText(wnd, ID_LEFTMARGIN, marg);
  490.                 PutItemText(wnd, ID_RIGHTMARGIN, marg);
  491.             }
  492.             for (mar = LINESPAGE; mar >= 0; --mar)    {
  493.                 sprintf(marg, "%3d", mar);
  494.                 PutItemText(wnd, ID_TOPMARGIN, marg);
  495.                 PutItemText(wnd, ID_BOTTOMMARGIN, marg);
  496.             }
  497.             cwnd = ControlWindow(&PrintSetup, ID_LEFTMARGIN);
  498.             SendMessage(cwnd, LB_SETSELECTION,
  499.                 CHARSLINE-cfg.LeftMargin, 0);
  500.             cwnd = ControlWindow(&PrintSetup, ID_RIGHTMARGIN);
  501.             SendMessage(cwnd, LB_SETSELECTION,
  502.                 CHARSLINE-cfg.RightMargin, 0);
  503.             cwnd = ControlWindow(&PrintSetup, ID_TOPMARGIN);
  504.             SendMessage(cwnd, LB_SETSELECTION,
  505.                 LINESPAGE-cfg.TopMargin, 0);
  506.             cwnd = ControlWindow(&PrintSetup, ID_BOTTOMMARGIN);
  507.             SendMessage(cwnd, LB_SETSELECTION,
  508.                 LINESPAGE-cfg.BottomMargin, 0);
  509.             return rtn;
  510.         case COMMAND:
  511.             if ((int) p1 == ID_OK && (int) p2 == 0)    {
  512.                 GetItemText(wnd, ID_PRINTERPORT, cfg.PrinterPort, 4);
  513.                 cwnd = ControlWindow(&PrintSetup, ID_LEFTMARGIN);
  514.                 cfg.LeftMargin = CHARSLINE -
  515.                     SendMessage(cwnd, LB_CURRENTSELECTION, 0, 0);
  516.                 cwnd = ControlWindow(&PrintSetup, ID_RIGHTMARGIN);
  517.                 cfg.RightMargin = CHARSLINE -
  518.                     SendMessage(cwnd, LB_CURRENTSELECTION, 0, 0);
  519.                 cwnd = ControlWindow(&PrintSetup, ID_TOPMARGIN);
  520.                 cfg.TopMargin = LINESPAGE -
  521.                     SendMessage(cwnd, LB_CURRENTSELECTION, 0, 0);
  522.                 cwnd = ControlWindow(&PrintSetup, ID_BOTTOMMARGIN);
  523.                 cfg.BottomMargin = LINESPAGE -
  524.                     SendMessage(cwnd, LB_CURRENTSELECTION, 0, 0);
  525.             }
  526.             break;
  527.         default:
  528.             break;
  529.     }
  530.     return DefaultWndProc(wnd, msg, p1, p2);
  531. }
  532.  
  533. static void FixTabMenu(void)
  534. {
  535.     char *cp = GetCommandText(&MainMenu, ID_TABS);
  536.     if (cp != NULL)    {
  537.         cp = strchr(cp, '(');
  538.         if (cp != NULL)    {
  539.             *(cp+1) = cfg.Tabs + '0';
  540.             if (GetClass(inFocus) == POPDOWNMENU)
  541.                 SendMessage(inFocus, PAINT, 0, 0);
  542.         }
  543.     }
  544. }
  545.  
  546. void PrepFileMenu(void *w, struct Menu *mnu)
  547. {
  548.     WINDOW wnd = w;
  549.     DeactivateCommand(&MainMenu, ID_SAVE);
  550.     DeactivateCommand(&MainMenu, ID_SAVEAS);
  551.     DeactivateCommand(&MainMenu, ID_DELETEFILE);
  552.     DeactivateCommand(&MainMenu, ID_PRINT);
  553.     if (wnd != NULL && GetClass(wnd) == EDITBOX) {
  554.         if (isMultiLine(wnd))    {
  555.             ActivateCommand(&MainMenu, ID_SAVE);
  556.             ActivateCommand(&MainMenu, ID_SAVEAS);
  557.             ActivateCommand(&MainMenu, ID_DELETEFILE);
  558.             ActivateCommand(&MainMenu, ID_PRINT);
  559.         }
  560.     }
  561. }
  562.  
  563. void PrepSearchMenu(void *w, struct Menu *mnu)
  564. {
  565.     WINDOW wnd = w;
  566.     DeactivateCommand(&MainMenu, ID_SEARCH);
  567.     DeactivateCommand(&MainMenu, ID_REPLACE);
  568.     DeactivateCommand(&MainMenu, ID_SEARCHNEXT);
  569.     if (wnd != NULL && GetClass(wnd) == EDITBOX) {
  570.         if (isMultiLine(wnd))    {
  571.             ActivateCommand(&MainMenu, ID_SEARCH);
  572.             ActivateCommand(&MainMenu, ID_REPLACE);
  573.             ActivateCommand(&MainMenu, ID_SEARCHNEXT);
  574.         }
  575.     }
  576. }
  577.  
  578. void PrepEditMenu(void *w, struct Menu *mnu)
  579. {
  580.     WINDOW wnd = w;
  581.     DeactivateCommand(&MainMenu, ID_CUT);
  582.     DeactivateCommand(&MainMenu, ID_COPY);
  583.     DeactivateCommand(&MainMenu, ID_CLEAR);
  584.     DeactivateCommand(&MainMenu, ID_DELETETEXT);
  585.     DeactivateCommand(&MainMenu, ID_PARAGRAPH);
  586.     DeactivateCommand(&MainMenu, ID_PASTE);
  587.     DeactivateCommand(&MainMenu, ID_UNDO);
  588.     if (wnd != NULL && GetClass(wnd) == EDITBOX) {
  589.         if (isMultiLine(wnd))    {
  590.             if (TextBlockMarked(wnd))    {
  591.                 ActivateCommand(&MainMenu, ID_CUT);
  592.                 ActivateCommand(&MainMenu, ID_COPY);
  593.                 ActivateCommand(&MainMenu, ID_CLEAR);
  594.                 ActivateCommand(&MainMenu, ID_DELETETEXT);
  595.             }
  596.             ActivateCommand(&MainMenu, ID_PARAGRAPH);
  597.             if (!TestAttribute(wnd, READONLY) &&
  598.                         Clipboard != NULL)
  599.                 ActivateCommand(&MainMenu, ID_PASTE);
  600.             if (wnd->DeletedText != NULL)
  601.                 ActivateCommand(&MainMenu, ID_UNDO);
  602.         }
  603.     }
  604. }
  605.  
  606.